package chapter03;

/**
 * Created by Miracle yaochengwei on 2022/4/4 10:49
 */
public class StringToBasicDetail {

    //编写一个 main 方法
    public static void main(String[] args) {


        String str = "hello";
//转成 int
        int n1 = Integer.parseInt(str); System.out.println(n1);
    }

    /**
     * Created by Miracle yaochengwei on 2022/4/4 11:45
     */
    public static class ArithmeticOperator {
        //演示算数运算符的使用
        public static void main(String[] args) {
            //使用
            System.out.println(10 / 4); //从数学来看是2.5, java中是 2
            System.out.println(10.0 / 4); //java、2.5  10.0是double
            //注释快捷键ctrl +/，再次输入ctrl +/取消注释
            double d = 10 / 4;//java中10 / 4 = 2, 2=>2.0 double是小数 2.0是double  2是int
            System.out.println(d);// 2.0
            //% 取模 ，取余
            // %  取模 ,取余
            System.out.println(10 % 3);//1
            System.out.println(-10 % 3);//-1
            System.out.println(10 % -3);//1
            System.out.println(-10 % -3);//-1
    //  在 %  的本质 看一个公式!!!! a % b = a - a / b * b
    // -10 % 3 => -10 - (-10) / 3 * 3 = -10 + 9 = -1
    // 10 % -3 = 10 - 10 / (-3) * (-3) = 10 - 9 = 1
    // -10 % -3 =	(-10) - (-10) / (-3) * (-3) = -10 + 9 = -1

    // %  取模 ,取余
    //  在 %  的本质 看一个公式!!!! a % b = a - a / b * b
    // -10 % 3 => -10 - (-10) / 3 * 3 = -10 + 9 = -1
    // 10 % -3 = 10 - 10 / (-3) * (-3) = 10 - 9 = 1
    // -10 % -3 =	(-10) - (-10) / (-3) * (-3) = -10 + 9 = -1

            int i = 10;
            i++;//自增等价于 i = i + 1; => i = 11
            ++i;//自增等价于  i = i + 1; => i = 12
            System.out.println("i=" + i);//12


            /*
            作为表达式使用
            前++：++i 先自增后赋值 后++：i++先赋值后自增
            */
            int j = 8;
            //int k = ++j; //等价 j=j+1; k=j;
            int k = j++; // 等价 k =j;j=j+1;
            System.out.println("k=" + k + "j=" + j);//8 9
        }
    }
}
